package com.craney.testLoader
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.events.ProgressEvent;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	public class LoadBar extends Sprite
	{
		private var progressPercentage:TextField = new TextField(); 
		private var load:URLLoader = new URLLoader();
//		private var addr:String = "D:\\备份\\eclipse3.3 plugins.rar"; 
//		private var addr:String = "http://bbs.daidai365.com/myfile/梁祝小提琴协奏曲.mp3"; 
		private var addr:String = "http://www.haolexing.com/upimg/media/0815/1_080815150728.mp3"; 
		
		private var url:URLRequest = new URLRequest(addr);
		private var perStr:String;
		
		private var progressBar:Shape = new Shape();
		
		public function LoadBar()
		{
			progressPercentage.border = true;
			progressPercentage.autoSize = TextFieldAutoSize.CENTER;
			
			load.addEventListener(ProgressEvent.PROGRESS, progress);
			load.addEventListener(Event.COMPLETE, complete);
			load.load(url);

			graphics.beginFill(0x0000FF);
			graphics.drawRect(0, 50, 100, 10);

			addChild(progressPercentage);
			addChild(progressBar);
		}
		private function progress(event:ProgressEvent):void
		{
			var percentage:Number = event.bytesLoaded / event.bytesTotal * 100;
			perStr = "percentage = " + percentage.toFixed(2) + "%"; 
			perStr += "\t\n" + (event.bytesLoaded / 1024).toFixed(3) + " K / " + (event.bytesTotal / 1024).toFixed(3) + " K "; 
			progressPercentage.text = perStr;
			trace(progressPercentage.text);
			drawProgress(percentage);
		}
		
		private function complete(event:Event):void
		{
			
		}
		private function netStatus(event:NetStatusEvent):void
		{
			trace("NetStatusEvent!");
		}
		
		private function drawProgress(prgrss:Number):void
		{
			progressBar.graphics.clear();
			progressBar.graphics.beginFill(0xFF00CC);
			progressBar.graphics.drawRect(0, 50, prgrss, 10);
		}
		
		
	}
}